package com.ruoyi.web.controller.examine.store;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.StoreExamine;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.RestaurantGoodsService;
import com.ruoyi.system.service.StoreExamineService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/examine/store/storeExamine")
public class StoreExamineController extends BaseController {
    @Resource
    private StoreExamineService storeExamineService;

    @Resource
    private RestaurantGoodsService restaurantGoodsService;

    @Log(title = "点餐质检", businessType = BusinessType.OTHER)
    @GetMapping("/list")
    public TableDataInfo list(StoreExamine examinePlan) {
        startPage();
        List<StoreExamine> list = storeExamineService.selectList(examinePlan);
        return getDataTable(list);
    }


    @Log(title = "点餐质检All", businessType = BusinessType.OTHER)
    @GetMapping("/listAll")
    public TableDataInfo listAll(StoreExamine examinePlan) {
        List<StoreExamine> list = storeExamineService.selectList(examinePlan);
        return getDataTable((list));
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success((storeExamineService.selectById(id)));
    }

    @Log(title = "点餐质检", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody StoreExamine examinePlan) {
        examinePlan.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        Boolean result = storeExamineService.create(examinePlan);
        if (result) {
            return success();
        }
        return error();
    }

    @Log(title = "点餐质检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody StoreExamine examinePlan) {
        examinePlan.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        examinePlan.setCheckTime(new Date());
        examinePlan.setInspector(SecurityUtils.getNickName());
        Boolean result = storeExamineService.update(examinePlan);
        if (result) {
            return success();
        }
        return error();
    }

    @Log(title = "点餐质检", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(storeExamineService.deleteById(id));
    }

}
